/**
 * 描述格式化日期的函数
 * @date 2020-09-17
 * @returns {any}
 */
function formatDate() {
    let date = new Date()
    // console.log(date)
    //获得年
    let year = date.getFullYear()
    // console.log(`year=${year}`)
    //9-->09   10-->10
    let month = (date.getMonth() + 1 + '').padStart(2, '0')
    //console.log(`month=${month}`)
    let dayOfmonth = (date.getDate() + 1 + '').padStart(2, '0')
    // console.log(`dayOfmonth=${dayOfmonth}`)
    //周中的天
    let dayOfweek = date.getDay()
    // console.log(`dayOfweek=${dayOfweek}`)
    let hour = (date.getHours() + 1 + '').padStart(2, '0')
    //console.log(`hour=${hour}`)
    let minute = (date.getMinutes() + 1 + '').padStart(2, '0')
    //console.log(`minute=${minute}`)
    let second = (date.getSeconds() + 1 + '').padStart(2, '0')
    // console.log(`second${second}`)
    let milliSecond = (date.getMilliseconds() + '').padStart(2, '0')

    let str = `${year}-${month+1}-${dayOfmonth} ${hour}:${minute}:${second}---${milliSecond}`
    return str
}
//页面加载结束执行的函数，只能写一次
onload = function () {
    //定时函数，1000=1s
    setInterval(function () {
        //向app元素中写内容
        applicationCache.innerHTML = '今天是' + formatDate()
    }, 1)
}

let data = new Date()
let year = data.getFullYear()
let month = data.getMonth() + 1
//5天后
let day = data.getDate() + 5
//5天后的对象
data = new Date(year + '-' + month + '' + day)
console.log(data.getDay())



//实现5天的倒计时
let date = new Date(2020, 9, 1, 8)
let today = new Date()
let seconds = parseInt((data.getTime() - today.getTime()) / 1000)

/**
 * 描述
 * @date 2020-09-18
 * @param {any} times 指定日期的秒数
 * @returns {any}
 */
function countDown(times) {
    //递归边界
    if (times <= 0) {
        return
    }
    let d = parseInt(times / 86400)
    let h = parseInt((times - d * 86400) / 3600)
    h = (h + '').padStart(2, '0')
    let m = parseInt((times - d * 86400 - h * 3600) / 60)
    m = (m + '').padStart(2, '0')
    let s = times - d * 86400 - h * 3600 - m * 60
    s = (s + '').padStart(2, '0')
    let str = d + '天' + h + ':' + m + ':' + s
    //向id=app元素中写入html内容
    applicationCache.innerHtml = str
    //递归调用，1后执行一次
    setTimerout(function () {
        times--
        countDown(times)
    }, 1000)
}
countDown(seconds)